% this is the script for ploting particles(spheres) in 3D

clc;
clear all;
close all;

%Read sphere data file
f_id=fopen('FILE.dat');
XYZR=fscanf(f_id,'%f %f %f %f\n',[4 inf]);
f_return=fclose(f_id);

X=XYZR(1,:);
Y=XYZR(2,:);
Z=XYZR(3,:);
R=XYZR(4,:);

maxR=max(R);
minR=min(R);
NumSphere=size(R,2);

%Draw spheres
maxGrid=75;
minGrid=10;
sphereGrid=0;

%colormap (gray);

hold
for i=1:NumSphere
   sphereGrid=(R(i)-minR)/(maxR-minR);
   sphereGrid=sphereGrid*(maxGrid-minGrid)+minGrid;
   sphereGrid=round(sphereGrid);
   [x1,y1,z1]=sphere(sphereGrid);
   x1=x1*R(i);
   y1=y1*R(i);
   z1=z1*R(i);
   surf(x1+X(i),y1+Y(i),z1+Z(i))

end;

view(25,30);
box;
axis equal;
shading interp;
camlight left;


